﻿
namespace WebPattern.Core.Extensions.LINQ
{
    public class Range
    {
        public virtual int Min { get; set; }
        public virtual int Max { get; set; }

        public bool Contains(short value) {
            return value >= Min && value <= Max;
        }

        public bool Contains(int value) {
            return value >= Min && value <= Max;
        }

        public bool Contains(long value) {
            return value >= Min && value <= Max;
        }

        public bool Contains(float value) {
            return value >= Min && value <= Max;
        }

        public bool Contains(double value) {
            return value >= Min && value <= Max;
        }

        public bool Contains(decimal value) {
            return value >= Min && value <= Max;
        }

        public bool ContainsIgnoreNulls(short? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }

        public bool ContainsIgnoreNulls(int? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }

        public bool ContainsIgnoreNulls(long? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }
        
        public bool ContainsIgnoreNulls(float? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }
        
        public bool ContainsIgnoreNulls(double? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }

        public bool ContainsIgnoreNulls(decimal? value) {
            if (!value.HasValue)
                return true;
            return Contains(value.Value);
        }

        public override string ToString() {
            return string.Format("between {0} and {1}", Min, Max);
        }
    }
}
